package com.java110.mall.cart.smo.impl;


import com.java110.mall.cart.dao.IInoutOrderServiceDao;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.inoutOrder.InoutOrderDto;
import com.java110.intf.cart.IInoutOrderInnerServiceSMO;
import com.java110.po.inoutOrder.InoutOrderPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 出入库内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class InoutOrderInnerServiceSMOImpl extends BaseServiceSMO implements IInoutOrderInnerServiceSMO {

    @Autowired
    private IInoutOrderServiceDao inoutOrderServiceDaoImpl;


    @Override
    public int saveInoutOrder(@RequestBody InoutOrderPo inoutOrderPo) {
        int saveFlag = 1;
        inoutOrderServiceDaoImpl.saveInoutOrderInfo(BeanConvertUtil.beanCovertMap(inoutOrderPo));
        return saveFlag;
    }

    @Override
    public int updateInoutOrder(@RequestBody InoutOrderPo inoutOrderPo) {
        int saveFlag = 1;
        inoutOrderServiceDaoImpl.updateInoutOrderInfo(BeanConvertUtil.beanCovertMap(inoutOrderPo));
        return saveFlag;
    }

    @Override
    public int deleteInoutOrder(@RequestBody InoutOrderPo inoutOrderPo) {
        int saveFlag = 1;
        inoutOrderPo.setStatusCd("1");
        inoutOrderServiceDaoImpl.updateInoutOrderInfo(BeanConvertUtil.beanCovertMap(inoutOrderPo));
        return saveFlag;
    }

    @Override
    public List<InoutOrderDto> queryInoutOrders(@RequestBody InoutOrderDto inoutOrderDto) {

        //校验是否传了 分页信息

        int page = inoutOrderDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            inoutOrderDto.setPage((page - 1) * inoutOrderDto.getRow());
        }

        List<InoutOrderDto> inoutOrders = BeanConvertUtil.covertBeanList(inoutOrderServiceDaoImpl.getInoutOrderInfo(BeanConvertUtil.beanCovertMap(inoutOrderDto)), InoutOrderDto.class);

        return inoutOrders;
    }


    @Override
    public int queryInoutOrdersCount(@RequestBody InoutOrderDto inoutOrderDto) {
        return inoutOrderServiceDaoImpl.queryInoutOrdersCount(BeanConvertUtil.beanCovertMap(inoutOrderDto));
    }

    public IInoutOrderServiceDao getInoutOrderServiceDaoImpl() {
        return inoutOrderServiceDaoImpl;
    }

    public void setInoutOrderServiceDaoImpl(IInoutOrderServiceDao inoutOrderServiceDaoImpl) {
        this.inoutOrderServiceDaoImpl = inoutOrderServiceDaoImpl;
    }
}
